package com.hc.fdkgoods.service;

import com.hc.fdkgoods.dao.PushedBizSummaryDao;
import com.hc.fdkgoods.vo.ForwarderSupplierGroupVO;
import com.hc.fdkgoods.vo.ForwarderSupplierVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class PushedBizSummaryService {

    @Resource
    private PushedBizSummaryDao pushedBizSummaryDao;

    public List<ForwarderSupplierGroupVO> getPushedBizSummary(){
        List<ForwarderSupplierGroupVO> res = new ArrayList<>();

        List<ForwarderSupplierVO> list = pushedBizSummaryDao.queryPushedBiz();

        Map<String, List<ForwarderSupplierVO>> GroupName2ForwarderSup
                = list.stream().collect(Collectors.groupingBy(ForwarderSupplierVO::getGroupName));

        GroupName2ForwarderSup.forEach((groupName, suppliers) -> {
            ForwarderSupplierGroupVO forwarderSupplierGroupVO = new ForwarderSupplierGroupVO();

            ForwarderSupplierVO forwarderSupplierVO = suppliers.get(0);

            forwarderSupplierGroupVO.setGroupName(forwarderSupplierVO.getGroupName());
            forwarderSupplierGroupVO.setSupplierVOList(suppliers);

            res.add(forwarderSupplierGroupVO);
        });

        return res;
    }

}
